package com.xiaoqi.store.config;

import com.xiaoqi.store.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author Rookie Coder
 * @Description 配置类
 * @Date
 **/
@Configuration
public class LoginInterceptorConfig implements WebMvcConfigurer {

    /*
    * @Author xiaoqi
    * @Description  添加拦截器
    * @return
    **/
    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        // 创建拦截器对象
        HandlerInterceptor loginInterceptor = new LoginInterceptor();

        // 白名单
        List<String> patterns = new ArrayList<>();
        patterns.add("/bootstrap3/**");
        patterns.add("/css/**");
        patterns.add("/image/**");
        patterns.add("/js/**");
        patterns.add("/web/register.html");
        patterns.add("/web/login.html");
        patterns.add("/web/index.html");
        patterns.add("/web/product.html");
        patterns.add("/user/userLogin");
        patterns.add("/user/registUser");
        patterns.add("/user/checkUserName");
        patterns.add("/districts/**");
        patterns.add("/products/**");
        patterns.add("/ExcelController/**");
        // 省市区三级联动
        patterns.add("/districts");
        patterns.add("/web/index.html");
        patterns.add("/products/**");

        // 通过注册添加拦截器
        registry.addInterceptor(loginInterceptor).addPathPatterns("/**").excludePathPatterns(patterns);
    }
}
